﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PRET.ReportControlLib.Controls
{
    public partial class SetYearPanelSim2 : UserControl
    {
        public event ShowTeamAttEditorEventHandle switchMonthEvent;

        public SetYearPanelSim2()
        {
            InitializeComponent();
            InitializeYears();
        }

        public void EnableControls(bool sign)
        {
            this.dateTimePicker.Enabled = sign;
        }

        public DateTime GetSelectedYearMonth
        {
            get
            {
                string yearmonth = this.dateTimePicker.Value.ToString("yyyy-MM");
                return DateTime.Parse(yearmonth);
            }
        }

        private void InitializeYears()
        {
            this.dateTimePicker.MaxDate = DateTime.Today;
            this.dateTimePicker.Value = DateTime.Today;
        }

        private void dateTimePicker_ValueChanged(object sender, EventArgs e)
        {
            if (switchMonthEvent != null)
            {
                ShowTeamAttEditorEventArgs eventArg = new ShowTeamAttEditorEventArgs();
                eventArg.StartYear = this.GetSelectedYearMonth;
                switchMonthEvent(this, eventArg);
            }
        }
    }

    public delegate void ShowTeamAttEditorEventHandle(object sender, ShowTeamAttEditorEventArgs args);

    public class ShowTeamAttEditorEventArgs : EventArgs
    {
        public ShowTeamAttEditorEventArgs()
        { }
        private DateTime startYear;
        public DateTime StartYear
        {
            get { return startYear; }
            set { startYear = value; }
        }
    }
}
